package ecom.nopecom.account;

import ecom.nopecom.util.NopeLogger;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.PageFactory;

import ecom.nopecom.BasePage;
import ecom.nopecom.account.pagecontainer.LoginPageContainer;
import ecom.nopecom.util.Consumer;
import ecom.nopecom.util.NopComFactory;



public class Login extends BasePage {


    private static final NopeLogger LOGGER = NopComFactory.getLogger(BasePage.class);

    LoginPageContainer pageContainer = PageFactory.initElements(nopeDriver, LoginPageContainer.class);
	Registration registration = new Registration();
//	boolean LoggedInstatus = false;
	
	public void login(String username,String password)
	{
		
		//login code
		pageContainer.username.sendKeys(username);
		pageContainer.password.sendKeys(password);
		pageContainer.submit.click();
		
	}
	
	public void loginAndReg(String firstName, String lastName, String email, String username, String password)
	{
	
		login(username, password);
		if(isLoginFailed())
		registration.registerWithMandatoryFields(firstName, lastName, email, username, password);
	}

	private boolean isLoginFailed() {
		return false;
                //nopeDriver.isDisplayed("Login Sucess");
	}

	public void login(Consumer consumer)
	{
		login(consumer.getUsername(),consumer.getPassword());
		consumer.setUserLoggedInStatus(true);
	}
	public void goToLoginPage() {

		nopeDriver.navigate().to("http://demo.nopcommerce.com/login");
	}

	public String getWelcomeMessage() {
	
		return "";
	}

	@Override
	public WebElement getLandingElement() {
		return pageContainer.defaultElement;
	}


    
public void goToRegistrationPage() {
    nopeDriver.navigate().to("http://demo.nopcommerce.com/register");
    }
}